package org.zjt.chapter1.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.HttpServerExpectContinueHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-07-19 下午5:05
 * @see
 */
@Slf4j
public class CompressHttpServer extends  AbstractHttpServer {


    public static void main(String[] args) {
        new CompressHttpServer().start(8089);
    }

    @Override
    public ChannelInitializer<NioSocketChannel> getChannelInitializer() {
        return new ChannelInitializer<NioSocketChannel>() {
            @Override
            protected void initChannel(NioSocketChannel ch) throws Exception {
                ChannelPipeline pipeline = ch.pipeline();

                pipeline.addLast(new HttpServerCodec());

                pipeline.addLast(new HttpServerExpectContinueHandler());


                pipeline.addLast(new HttpHelloWorldServer.MyRequestHandler());

                // 写出压缩
                pipeline.addLast(new HttpContentCompressor());
            }
        };
    }
}
